using System.Collections;
using BCW.Friends;
using BCW.GameTypes.SkyBlock;
using I2.Loc;
using UnityEngine;

public class SkyBlockGameMode : TeamGameMode
{
	public override void StartRound()
	{
		base.StartRound();
		TDMController.instance.SetStartPVP(true);
		PlayerBehavior.MyPlayer.FirstSpawn(2f);
		CoroutineRunner.Invoke(2.5f, delegate
		{
			Debug.LogError("hideInterface from start");
			if (PlayerBehavior.MyPlayer.tController.enabled)
			{
				GameInfoWindow.instance.HideInterface();
				MapWindow.instance.gameObject.SetActive(true);
				GameController.instance.showWindowGame();
				SkyBlockController.instance.UpdateColors();
				SkyBlockController.instance.InitPointer();
				SkyBlockController.instance.ShowCaptureFlagNotification();
			}
		});
	}

	public override void RestartRound()
	{
		base.RestartRound();
		if (BCWFlagManager.instance != null)
		{
			BCWFlagManager.instance.winerTeam = PunTeams.Team.none;
		}
		if (BCWFlagController.instance != null)
		{
			BCWFlagController.instance.winnerTeam = TDMResult.None;
			if (!PhotonNetwork.isMasterClient)
			{
				BCWFlagController.instance.Reset();
			}
		}
		if (GameController.instance.playerScript != null)
		{
			GameController.instance.playerScript.Points = 0;
		}
		CoroutineRunner.Instance.StartCoroutine(DelayInSkyBlock());
	}

	private IEnumerator DelayInSkyBlock()
	{
		yield return new WaitForSeconds(2.5f);
		TDMController.instance.WaitTeamAndSpawnPointOnRestart(RestartSkyBlock);
	}

	private void RestartSkyBlock()
	{
		if (FriendsUIGame.instance != null)
		{
			FriendsUIGame.instance.CleanInvitePlayer();
		}
		CoroutineRunner.Instance.StartCoroutine(WaitRestartSkyBlock());
	}

	private IEnumerator WaitRestartSkyBlock()
	{
		yield return CoroutineRunner.Instance.StartCoroutine(TDMController.instance.WaitRestartTDM());
		SkyBlockController.instance.UpdateColors();
		SkyBlockController.instance.InitPointer();
		SkyBlockController.instance.ShowCaptureFlagNotification();
		PlayerBehavior.MyPlayer.CorrectFlagAfterChangeTeam();
	}

	public override void EndRound()
	{
		SkyBlockController.instance.Reset();
		BCWFlagManager.instance.beganRestart = false;
	}

	public override string EndGameModeTitle()
	{
		return ScriptLocalization.Get("Game_Common/sb_over");
	}
}
